package me.ljd.yigo.service;

import java.util.ArrayList;

import com.bokesoft.yigo.common.util.TypeConvertor;
import com.bokesoft.yigo.mid.base.DefaultContext;
import com.bokesoft.yigo.mid.connection.IDBManager;
import com.bokesoft.yigo.mid.service.IExtService;

import me.ljd.yigo.utils.DBManagerUtil2;

public class ChangeDBManagerService implements IExtService {
	

	public ChangeDBManagerService() {
		System.out.println("ChangeDBManagerService()");
		DBManagerUtil2.init();
	}

	@Override
	public Object doCmd(DefaultContext context,ArrayList<Object> paras) throws Throwable {
		int index = 0;
		if(paras != null && paras.size()>0) {
			index = TypeConvertor.toInteger(paras.get(0));
		}
		//DBManagerUtil2.setDBManager(context.getDBManager());
		context.getDBManager().close();
		IDBManager dbManager = DBManagerUtil2.getDBManager(index);
		context.setDBManager(dbManager);//java.sql.SQLException: The prepared statement has been finalized
		return 1;
	}

}
